// pages/evaluateHistory/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList:[],
    newData:[],
    opacity:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDataListAction(()=>{

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getDataListAction(()=>{
      wx.stopPullDownRefresh()
    })
  },
  getDataListAction(callBack){
    var that = this
    app.post(app.Apis.GET_QUESTION_LIST,{
      userId:app.userId
    },result=>{
      if(result.dataList){
        that.setData({
          dataList:result.dataList,
          opacity: result.dataList.length > 0 ? 1 : 0
        })
        that.setNewDataArr()
        callBack()
      }
    })
  },

  clickLookDetail(e){

    let id = this.data.dataList[e.detail.index].id
    wx.navigateTo({
      url: '/pages/evaluateHistoryDetail/index?questionId=' + id,
    })
  },
  setNewDataArr(){
    var newD = JSON.parse(JSON.stringify(this.data.dataList))
    for(var i = 0;i<newD.length;i++){

      if (newD[i].lastReplyMessage!=null){
        var newContent = newD[i].lastReplyMessage
        console.log(newContent, newContent.length)
        if (newContent.length < 10) {
          newD[i].hasTwoLine = false
        } else if (newContent.length < 28) {
          newD[i].lastReplyMessage = newContent.substring(0, 10) + '...'
          newD[i].hasTwoLine = false
        } else {
          newD[i].lastReplyMessage = newContent.substring(0, 28) + '...'
          newD[i].hasTwoLine = true
        }
        console.log(newD[i].hasTwoLine)

      }
    
    }
    this.setData({
      newData: newD
    })
  }
})